#!/bin/bash

if [[ "$PLATFORM" == "arm64" ]]; then
  TARGET_PLATFORM="linux/arm64"
  GOARCH="arm64"
else
  TARGET_PLATFORM="linux/amd64"
  GOARCH="amd64"
fi
GOOS="linux"

# 镜像名称和标签
IMAGE_NAME="txwl-ops/prometheus-alert"
IMAGE_TAG="latest"

# 创建并使用新的buildx构建实例
docker buildx create --name mybuilder --use

# 启动多平台构建
# 传递GOOS和GOARCH作为构建参数
docker buildx build \
  --platform ${TARGET_PLATFORM} \
  --build-arg GOOS=${GOOS} \
  --build-arg GOARCH=${GOARCH} \
  -t ${IMAGE_NAME}:${IMAGE_TAG} . --load

# 删除buildx构建实例
docker buildx rm mybuilder
